
angular.module('app').controller('dailyTackCtrl',['$scope','$rootScope','$http','$state','utils','activity'
    ,function ($scope,$rootScope,$http,$state,utils,activity) {
        if($scope.isapp){
            appload={
                CallBack:function (type) {
                    if(type=='822'){
                        rendTackList();
                    }
                }
            };
        }

        $scope.$on('$viewContentLoaded', function(event) {
            setTimeout(function () {
                if($rootScope.isapp) {
                    wv.setHeader('任务中心','0','-','0')
                }
            },300)
        });

        $scope.toActivity=function (task) {
             {
                 if('0'==task.isFinish){
                     return ;
                 }else {
                     if($scope.isapp){
                           switch (task.id){
                               case 1:
                                   wv.go('2');
                                   break
                               case 2:
                                   wv.go('3');
                                   break
                               case 3:
                                   if($scope.isCheck()){
                                       wv.go('4');
                                   }
                                   break
                               case 4:
                                   if($scope.isCheck('pc')){
                                       wv.go('5');
                                   }
                                   break
                               case 5:
                                   if($scope.isCheck()){
                                       wv.go('6');
                                   }
                                   break
                               case 6:
                                   if($scope.isCheck()){
                                       wv.go('1');
                                   }
                                   break
                               case 7:
                                   $state.go('integral_sign');
                                   break
                         }
                     }else {
                         switch (task.id){
                             case 1: /*注册*/
                                 $state.go('register');
                                 break
                             case 2:  /*实名认证*/
                                 $state.go('Realname');
                                 break
                             case 3: /*绑定银行卡*/
                                 if($scope.isCheck()){
                                     $state.go('BindBank');
                                 }
                                 break
                             case 4:  /*评测*/
                                 if($scope.isCheck('pc')){
                                     $state.go('02_Evaluation');
                                 }
                                 break
                             case 5:/*充值*/
                                 if($scope.isCheck()){
                                     $state.go('PayOne');
                                 }
                                 break
                             case 6:/*购买*/
                                 if($scope.isCheck()){
                                     $state.go('all');
                                 }
                                 break
                             case 7:/*签到*/
                                 $state.go('integral_sign');
                                 break
                         }
                     }
                 }

            }
        };


        /**
         * 获取任务列表
         * @returns {Promise}
         * 设置完成的任务
         */
        function rendTackList() {
            $http.get(utils.integralSys, {
                params: {
                    header: utils.header("300310"),
                    body: {
                        userCode:activity.getSoloCode(), //afdasdfas
                    }
                }
            }).then(function (res) {
                if(res.header.re_code == "0000") {
                    $scope.tasks=res.body.tasks;
                    $scope.show=true;

                }
            })
        }



        setTimeout(function () {
            rendTackList();
        },300);



    $scope.getImgPath=function (type) {
        var src
      switch (type){
          case 1:
              src ="image/integral/regist.png";
              break
          case 2:
              src ="image/integral/real_name.png";
              break
          case 3:
              src ="image/integral/bind_bc.png";
              break
          case 4:
              src ="image/integral/first_reviews.png";
              break
          case 5:
              src ="image/integral/recharge.png";
              break
          case 6:
              src ="image/integral/first_make_money.png";
              break
          case 7:
              src ="image/integral/sign.png";
              break

      }
        return src;
    }



        $scope.getLogoPath=function (type) {
            var src
             if(type==7){
                 src='image/integral/daily_logo.png'
             }else {
                 src='image/integral/integral_logo.png'
             }
            return src;
        }

        $scope.getBonuses=function (task) {
            if(task.id==7){
                return''
            }else {
                return task.bonuses+'积分';
            }
        };

        $scope.complete=function (task) {

            if('0'==task.isFinish){
                return '已完成'
            }else {
                return '未完成'
            }
        };


        $scope.showStyle=function (task) {
            if('0'==task.isFinish){
                return true
            }else {
                return false
            }
        }

        $scope.isCheck=function (type) {
            if($scope.tasks){
                for (var i = 0; i < $scope.tasks.length; i++) {
                    var obj = $scope.tasks[i];
                   if(obj.id==2&&'1'==obj.isFinish){
                       if($scope.isapp){
                            wv.go('3');
                       }else {/*实名认证*/
                           $state.go('Realname');
                       }
                       return  false;
                   }
                   if('pc'==type)return true;
                    if(obj.id==3&&'1'==obj.isFinish){
                        if($scope.isapp){
                            wv.go('4');
                        }else {/*绑卡*/
                            $state.go('BindBank');
                        }
                        return  false;
                    }
                }
            }
                return true
        }



}])